﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ClassLibrary.DAO;

public partial class ucControl_ucListTinTucSuKien : System.Web.UI.UserControl
{
    TblMenuChildDAO menuChildDAO = new TblMenuChildDAO(Global.CONNECTION_STRING);
    TblMenuParrentDAO menuPaDAO = new TblMenuParrentDAO(Global.CONNECTION_STRING);
    TblItemsDAO itemDAO = new TblItemsDAO(Global.CONNECTION_STRING);
    TblTinTucSuKienDAO tintucDAO = new TblTinTucSuKienDAO(Global.CONNECTION_STRING);

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadMenuPa();        
            LoadItemLeft();
            LoadDongXe();
            LoadTinTuc();
        }
    }

    private void LoadDongXe()
    {
        rpDongxe.DataSource = menuPaDAO.GetAll();
        rpDongxe.DataBind();
    }

    private void LoadMenuPa()
    {
        rpMenuPa.DataSource = menuPaDAO.GetAll();
        rpMenuPa.DataBind();
    }

    private void LoadItemLeft()
    {
        rpItemLEft.DataSource = itemDAO.GetItem_New();
        rpItemLEft.DataBind();
    }

    private void LoadTinTuc()
    {
        rpTinTuc.DataSource = tintucDAO.GetTinTucSK();
        rpTinTuc.DataBind();
    }

    protected void rpMenuPa_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            Repeater reChildMenuLeft = (Repeater)e.Item.FindControl("rpmenuChild");
            HiddenField hidIDMenuPLeft = (HiddenField)e.Item.FindControl("hid");
            hidIDMenuPLeft.Value = DataBinder.Eval(e.Item.DataItem, "IDMenuParent").ToString();

            string id = hidIDMenuPLeft.Value;
            if (reChildMenuLeft != null)
            {
                reChildMenuLeft.DataSource = menuChildDAO.GetCateChild_ByIDParrent(Global.ConvertToInt(id));
                reChildMenuLeft.DataBind();
            }
        }
    }

  

   
}